import 'package:number_spark_flutter/style/ns_style.dart';
import 'package:number_spark_flutter/widgets/brick/ns_brick.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class NSDialogUtil {
  ///提示信息弹框|输入框弹框
  static void showConfirmDialog(
    String title, {
    String description = "",
    String? cancelString,
    bool isShowCancel = true,
    String? sureString,
    Function? sureAction,
    Function? cancelAction,
    bool isInput = false,
    TextEditingController? textEditingController,
    String? placeHolder,
    TextInputType? keyboardType = TextInputType.text,
    Widget? customWidget,
    bool isDelete = false,
  }) {
    Get.dialog(Scaffold(
      backgroundColor: Colors.transparent,
      body: Center(
        child: WillPopScope(
          onWillPop: () async {
            return false;
          },
          child: NSWrap(
            color: Colors.white,
            margin: EdgeInsets.symmetric(horizontal: 30.w),
            radius: 13.w,
            wrapAlignment: WrapAlignment.center,
            children: [
              if (title.isNotEmpty)
                NSText(
                  margin: EdgeInsets.only(top: 16.w),
                  text: title,
                  textAlign: TextAlign.center,
                  fontSize: 15.sp,
                  shrinkWrap: false,
                  textColor: kAppTextColor,
                  fontWeight: FontWeight.w500,
                ),
              customWidget ??
                  (isInput
                      ? NSContainer(
                          padding: EdgeInsets.symmetric(horizontal: 18.w),
                          margin: EdgeInsets.only(left: 22.w, right: 22.w, top: 12.w),
                          color: kAppColor('#F7F7F7'),
                          radius: 12.w,
                          height: 44.w,
                          alignment: Alignment.center,
                          strokeWidth: 1.w,
                          strokeColor: Colors.black,
                          child: TextFormField(
                            cursorColor: kAppThemeColor,
                            //光标颜色
                            keyboardType: keyboardType,
                            inputFormatters: [LengthLimitingTextInputFormatter(12)],
                            controller: textEditingController,
                            maxLines: 1,
                            autofocus: false,
                            style: TextStyle(fontSize: 14.sp, color: kAppTextColor, fontWeight: FontWeight.w500),
                            decoration: InputDecoration(
                                border: const OutlineInputBorder(borderSide: BorderSide.none),
                                hintText: placeHolder ?? '',
                                hintStyle: TextStyle(color: kAppColor('#AAAAAA'), fontWeight: FontWeight.normal, fontSize: 14.sp),
                                contentPadding: EdgeInsets.zero),
                            onChanged: (value) {
                              // action(value);
                            },
                          ),
                        )
                      : Padding(
                          padding: EdgeInsets.only(left: 15.w, right: 15.w, top: 18.w, bottom: 5.w),
                          child: Text(
                            description,
                            style: TextStyle(
                              fontSize: 14.sp,
                              color: kAppTextColor,
                            ),
                          ),
                        )),
              NSRow(
                margin: EdgeInsets.all(18.w),
                children: [
                  if (isShowCancel)
                    Expanded(
                      child: NSText(
                        height: 44.w,
                        radius: 12.w,
                        alignment: Alignment.center,
                        color: kAppColor('#F7F7F7'),
                        text: cancelString ?? 'Cancel',
                        fontSize: 14.sp,
                        textColor: kAppTextColor,
                        fontWeight: FontWeight.w500,
                        onTap: () {
                          Get.back();
                          cancelAction?.call();
                        },
                      ),
                    ),
                  SizedBox(
                    width: 36.w,
                  ),
                  // if (userCenterLogic == null)
                  Expanded(
                      child: NSText(
                    text: sureString ?? 'Sure',
                    height: 44.w,
                    radius: 12.w,
                    textColor: isDelete ? kAppColor('#FF5140') : kAppThemeColor,
                    fontWeight: FontWeight.bold,
                    fontSize: 14.sp,
                    color: isDelete ? kAppColor('#FFF4F3') : kAppThemeColor.withOpacity(0.1),
                    textAlign: TextAlign.center,
                    alignment: Alignment.center,
                    onTap: () {
                      Get.back();
                      sureAction?.call();
                    },
                  ))
                ],
              ),
            ],
          ),
        ),
      ),
    ));
  }
}
